package com.happy.unitconvert.common.controller;

import com.happy.unitconvert.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * 基础Controller
 * 提供系统基础信息接口
 */
@Tag(name = "系统基础接口", description = "系统健康检查、版本信息等基础接口")
@RestController
@RequestMapping("/api/v1/system")
public class BaseController {

  @Operation(summary = "健康检查", description = "检查系统运行状态")
  @GetMapping("/health")
  public Result<Map<String, Object>> health() {
    Map<String, Object> data = new HashMap<>();
    data.put("status", "UP");
    data.put("timestamp", LocalDateTime.now());
    data.put("application", "UnitConvert API");
    data.put("version", "1.0.0");

    return Result.success("系统运行正常", data);
  }

  @Operation(summary = "获取系统信息", description = "获取系统版本、环境等信息")
  @GetMapping("/info")
  public Result<Map<String, Object>> info() {
    Map<String, Object> data = new HashMap<>();
    data.put("application", "UnitConvert API");
    data.put("version", "1.0.0");
    data.put("description", "为Android、iOS、小程序等提供统一的单位转换API服务");
    data.put("javaVersion", System.getProperty("java.version"));
    data.put("springBootVersion", "3.0.2");
    data.put("timestamp", LocalDateTime.now());

    return Result.success(data);
  }

  @Operation(summary = "API版本信息", description = "获取API版本和支持的功能")
  @GetMapping("/version")
  public Result<Map<String, Object>> version() {
    Map<String, Object> data = new HashMap<>();
    data.put("apiVersion", "v1");
    data.put("applicationVersion", "1.0.0");
    data.put("supportedFeatures", new String[] {
        "长度单位转换",
        "重量单位转换",
        "温度单位转换",
        "面积单位转换",
        "体积单位转换",
        "压力单位转换",
        "速度单位转换"
    });
    data.put("buildTime", LocalDateTime.now());

    return Result.success(data);
  }
}
